/*******************************************************************************
 * Copyright (c) 2012, 2013 XML-Print Project.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     XML-Print Project - initial API and implementation
 ******************************************************************************/
package info.xmlprint.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.apache.log4j.Logger;

public class Utf8ToAnsi {
	private static Logger logger = Logger.getLogger(Utf8ToAnsi.class.getName());

	public static String Decode(String str) {
		String s = null;
		try {
			s = URLEncoder.encode(str, "UTF-8");
			s = s.replaceAll("%", "y");
			s = s.replace("+", "x");
		} catch (UnsupportedEncodingException e) {
			logger.error("", e);
			e.printStackTrace();
		}

		return s;
	}

	public static String Endcode(String str) {
		String s = null;
		try {
			s = new String(str.getBytes("UTF-8"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			logger.error("", e);
			e.printStackTrace();
		}
		return s;
	}
}
